package com.example.spring.boot.rabbitmq.configuration;

/**
 * <p>
 * TopicExchangeConfig
 * </p>
 *
 * @author weixin
 * @date 2023/3/14 15:15
 */

import com.example.spring.boot.rabbitmq.constant.TopicExchangeConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 主题交换机配置
 *
 * *  (星号) 用来表示一个单词 (必须出现的)
 * #  (井号) 用来表示任意数量（零个或多个）单词
 * @author sh.Liu
 * @date 2021-08-23 15:49
 */
@Configuration
public class TopicExchangeConfig {

    @Bean
    public Queue topicQueue() {
        return new Queue(TopicExchangeConstant.TOPIC_QUEUE, true);
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue(TopicExchangeConstant.TOPIC_QUEUE2, true);
    }

    @Bean
    public Queue topicQueue3() {
        return new Queue(TopicExchangeConstant.TOPIC_QUEUE3, true);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TopicExchangeConstant.TOPIC_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingTopicExchange(Queue topicQueue, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue).to(topicExchange).with(TopicExchangeConstant.TOPIC_ROUTING_KEY);
    }

    @Bean
    public Binding bindingTestTopicExchange(Queue topicQueue2, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with(TopicExchangeConstant.TEST_TOPIC_ROUTING_KEY);
    }

    @Bean
    public Binding bindingAllTopicExchange(Queue topicQueue3, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue3).to(topicExchange).with(TopicExchangeConstant.ALL_TOPIC_ROUTING_KEY);
    }
}
